/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.pc9.pswing.util;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 *
 * @author paulocanedo
 */
public class GenericIconFactory {

    private static Map<String, Icon> cacheMap = new HashMap<String, Icon>();

    public static Icon getIconInCache(String keyname) {
        return cacheMap.get(keyname);
    }

    public static Icon setIconInCache(String keyname, Icon icon) {
        cacheMap.put(keyname, icon);
        return icon;
    }

    public static Icon getSystemIcon(String category, String name, int size) {
        String keyName = category + "." + name;
        Icon iconCache = getIconInCache(keyName);
        if (iconCache != null) {
            return iconCache;
        }

        String resourceLocale = "/br/com/pc9/pswing/components/resources/icons/Faenza-Cupertino/";
        String localeName = String.format("%s%s/%d/%s.png", resourceLocale, category, size, name);
        URL resource = GenericIconFactory.class.getResource(localeName);
        return new ImageIcon(resource);
    }
}
